package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.OperateDeviceAuthCodeGetDevicePageDTO;
import com.itlong.cloud.POJO.DTO.operate.OperateDeviceAuthCodeGetPageDTO;
import com.itlong.cloud.POJO.VO.operate.OperateDeviceAuthCodeGetDevicePageVO;
import com.itlong.cloud.POJO.VO.operate.OperateDeviceAuthCodeGetPageVO;
import com.itlong.cloud.operate.service.IOperateDeviceAuthCodeService;
import com.itlong.cloud.project.operate.IOperateDeviceAuthCodeServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <desc>
 *      设备授权码管理暴露接口实现类
 * </desc>
 *
 * @createDate 2019/01/16
 */
@RestController
public class OperateDeviceAuthCodeServiceResource implements IOperateDeviceAuthCodeServiceClient {

    @Autowired
    private IOperateDeviceAuthCodeService iOperateDeviceAuthCodeService;

    /**
     * <desc>
     *      分页获取设备授权码
     * </desc>
     *
     * @param operateDeviceAuthCodeGetPageDTO 获取设备授权码列表DTO
     * @return 分页获取结果
     * @author wangzhi
     * @createDate 2019/01/16
     */
    @Override
    @PostMapping(path = "operate/deviceAuthCode/getPage")
    public Page<OperateDeviceAuthCodeGetPageVO> getPage(@RequestBody OperateDeviceAuthCodeGetPageDTO operateDeviceAuthCodeGetPageDTO) throws Exception {
        return iOperateDeviceAuthCodeService.getPage(operateDeviceAuthCodeGetPageDTO);
    }

    /**
     * <desc>
     *      新增设备授权码
     * </desc>
     *
     * @param baiduAuthCode 百度识别授权码，多个用英文逗号相连
     * @return 1成功，0失败
     * @author wangzhi
     * @createDate 2019/01/16
     */
    @Override
    @PostMapping(path = "operate/deviceAuthCode/saveDeviceAuthCode")
    public Integer saveDeviceAuthCode(@RequestParam("baiduAuthCode") String baiduAuthCode) throws Exception {
        return iOperateDeviceAuthCodeService.saveDeviceAuthCode(baiduAuthCode);
    }

    /**
     * <desc>
     *      查询单个设备授权码
     * </desc>
     *
     * @param operateDeviceAuthCodeGetPageDTO 获取设备授权码列表DTO
     * @return 单个设备授权码
     * @author wangzhi
     * @createDate 2019/01/21
     */
    @Override
    @PostMapping(path = "operate/deviceAuthCode/getOne")
    public OperateDeviceAuthCodeGetPageVO getOne(@RequestBody OperateDeviceAuthCodeGetPageDTO operateDeviceAuthCodeGetPageDTO) throws Exception {
        return iOperateDeviceAuthCodeService.getOne(operateDeviceAuthCodeGetPageDTO);
    }

    /**
     * <desc>
     *      获取设备授权码相关设备列表
     * </desc>
     *
     * @param operateDeviceAuthCodeGetDevicePageDTO 获取设备授权码相关设备列表DTO
     * @return 获取设备授权码相关设备列表分页结果
     * @author wangzhi
     * @createDate 2019/03/12
     */
    @Override
    @PostMapping(path = "operate/deviceAuthCode/getDevicePage")
    public Page<OperateDeviceAuthCodeGetDevicePageVO> getDevicePage(@RequestBody OperateDeviceAuthCodeGetDevicePageDTO operateDeviceAuthCodeGetDevicePageDTO) throws Exception {
        return iOperateDeviceAuthCodeService.getDevicePage(operateDeviceAuthCodeGetDevicePageDTO);
    }

    /**
     * <desc>
     *      购买（设备绑定设备授权码）
     * </desc>
     *
     * @param projectId    项目编号
     * @param deviceUnique 设备序列号，多个逗号相连
     * @return 0-失败 1-成功
     * @author wangzhi
     * @createDate 2019/03/12
     */
    @Override
    @PostMapping(path = "operate/deviceAuthCode/buy")
    public Integer buy(@RequestParam("projectId") String projectId, @RequestParam("deviceUnique") String deviceUnique) throws Exception {
        return iOperateDeviceAuthCodeService.buy(projectId,deviceUnique);
    }

    /**
     * <desc>
     *      解绑（设备与设备授权码解除绑定）
     * </desc>
     *
     * @param operateDeviceAuthCodeGetPageDTO 获取设备授权码列表DTO
     * @return 0-失败 1-成功
     * @author wangzhi
     * @createDate 2019/03/12
     */
    @Override
    @PostMapping(path = "operate/deviceAuthCode/unbind")
    public Integer unbind(@RequestBody OperateDeviceAuthCodeGetPageDTO operateDeviceAuthCodeGetPageDTO) throws Exception {
        return iOperateDeviceAuthCodeService.unbind(operateDeviceAuthCodeGetPageDTO);
    }
}
